package com.fs.sale.controller;

import com.fs.common.core.pojo.Customer;
import com.fs.common.core.vo.AjaxResult;
import com.fs.sale.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("customer")
public class CustomerController {
    @Autowired
    CustomerService customerService;

//    查询所有客户
    @PostMapping("list")
    public AjaxResult SelectAll(){
        List<Customer> customerList=customerService.selectAll();
        AjaxResult ajaxResult=new AjaxResult();
        ajaxResult.put("customerList",customerList);
        return ajaxResult;
    }

    @GetMapping("select")
    public AjaxResult Select( Customer customer){
        List<Customer> customerList=customerService.query(customer);
        AjaxResult ajaxResult=new AjaxResult();
        ajaxResult.put("customerList",customerList);
        return ajaxResult;
    }

    @PostMapping("insert")
    public  AjaxResult insert(Customer customer){
        if(customerService.addCustomer(customer)>0){
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }

    @PostMapping("delete")
    public AjaxResult delete(int id){
        if(customerService.deleteCustomer(id)>0){
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }
}
